import random

class TestDataGenerator:
    """测试数据生成器"""
    
    @staticmethod
    def generate_random_matrix(rows, cols, density=0.5):
        """
        生成随机矩阵
        :param rows: 行数
        :param cols: 列数  
        :param density: '1'的密度 (0-1之间)
        :return: 二维矩阵
        """
        matrix = []
        for i in range(rows):
            row = []
            for j in range(cols):
                if random.random() < density:
                    row.append('1')
                else:
                    row.append('0')
            matrix.append(row)
        return matrix
    
    @staticmethod
    def generate_square_matrix(size, square_size):
        """
        生成包含指定大小正方形的矩阵
        :param size: 矩阵大小 (size x size)
        :param square_size: 正方形大小
        :return: 二维矩阵和期望结果
        """
        matrix = [['0'] * size for _ in range(size)]
        
        # 随机选择正方形的起始位置
        start_row = random.randint(0, size - square_size)
        start_col = random.randint(0, size - square_size)
        
        # 填充正方形区域
        for i in range(start_row, start_row + square_size):
            for j in range(start_col, start_col + square_size):
                matrix[i][j] = '1'
        
        expected_area = square_size * square_size
        return matrix, expected_area
    
    @staticmethod
    def generate_all_zeros(rows, cols):
        """生成全0矩阵"""
        return [['0'] * cols for _ in range(rows)]
    
    @staticmethod
    def generate_all_ones(rows, cols):
        """生成全1矩阵"""
        return [['1'] * cols for _ in range(rows)]
    
    @staticmethod
    def generate_edge_cases():
        """生成边界情况测试用例"""
        return [
            ([], 0, "空矩阵"),
            ([["0"]], 0, "单个0"),
            ([["1"]], 1, "单个1"),
            ([["1", "0", "1", "1"]], 1, "单行"),
            ([["1"], ["0"], ["1"]], 1, "单列"),
            ([["1", "1"], ["1", "1"]], 4, "2x2全1"),
            ([["1", "0"], ["0", "1"]], 1, "2x2对角")
        ]
